import { createRouter, createWebHashHistory } from 'vue-router'
import store from '@/store'

const routes = [
  {
		path:'/',
		name: 'home',
		redirect: '/main'
	},
  {
		path: '/main',
		name: 'main',
		component: () => import('../views/Main.vue'),
		redirect: '/main/org/Department',
		children: [
			{
			  path: '/main/org/Department',
			  name: 'department',
			  component: () => import('../views/org/DepartmentView.vue'),
			},
			{
				path: '/main/org/Employee',
				name: 'employee',
				component: () => import('../views/org/EmployeeView.vue'),
			},
			{
				path: '/main/system/Menu',
				name: 'menu',
				component: () => import('../views/org/MenuView.vue'),
			},
			{
				path: '/main/system/Permission',
				name: 'permission',
				component: () => import('../views/org/PermissionView.vue'),
			},
			{
				path: '/main/system/Role',
				name: 'role',
				component: () => import('../views/org/RoleView.vue'),
			},
		]
	},
	{
		path: '/login',
		name: 'login',
		component: () => import('../views/Login.vue'),
	}
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

//路由守卫
router.beforeEach((to,from,next)=>{
	console.log('路由守卫：',to.path);
	store.state.elMenuActive = to.path;
	next(); //放行
})

export default router
